<?php
define('ACTION_GOORNOT', 'go');
define('ACTION_DESTINYINFO', 'getp');

switch(true){
	case (strcmp($action, ACTION_GOORNOT) == 0):
		if(!empty($_GET['gid']) && !empty($_GET['pid']) && ($_GET['go'] == 1 || $_GET['go'] == 0)){
			$idPlace = $_GET['pid'];
			$idGroup = $_GET['gid'];
			$go = $_GET['go'];
			
			$group = new Group();
			$place = new Place();
			if($group->loadFromDB($idGroup)){ //Carga y comprueba el grupo
				if($place->loadFromDB($idPlace)){ //Carga y comprueba el lugar.
					if($user->isInvitedInGroup($idGroup)){
						if($user->isPlaceInGroup($idPlace, $idGroup)){
							$user->goPlace4Group($idPlace, $idGroup, $go);
							$result = array('status'=> NO_ERR);
						} else {
							$result = array('status' => ERR_NOT_PLACE_INGROUP);
						}
					} else {
						$result = array('status' => ERR_NOTINGROUP);
					}
				} else {
					$result = array('status' => ERR_PLACE_NOTEXISTS);
				}
			} else {
				$result = array('status' => ERR_GROUP_NOTEXISTS);
			}
		} else {
			$result = array('status' => ERR_BAD_PARAMS);
		}
		break;
	case (strcmp($action, ACTION_DESTINYINFO) == 0):
		if(!empty($_GET['gid']) && !empty($_GET['pid'])){
			$idPLace = $_GET['pid'];
			$idGroup = $_GET['gid'];
			
			if($group->loadFromDB($idGroup)){ //Carga y comprueba el grupo
				if($newPlace->loadFromDB($idNewPlace)){ //Carga y comprueba el lugar.
					$user->getDestinyInfo($idPlace, $idGroup);
					$result = array('status'=> NO_ERR);
				} else {
					$result = array('status' => ERR_PLACE_NOTEXISTS);
				}
			} else {
				$result = array('status' => ERR_GROUP_NOTEXISTS);
			}			
		}
		break;
	default:
		$result = array('status' => ERR_GENERAL);
}

?>